<?php
class Content_Model extends CI_Model{
	//构造函数
	function __construct()
	
	{
		parent::__construct();
	}
	
	/************************************
	 * 获取单篇日志内容
	 * 
	 * @access public
	 * @param int $id
	 * @return array $res->$result_array();
	 * 
	 ***********************************/
	function get_content($id)
	{
		
		$sql = "SELECT * FROM `mb_webblogs` WHERE `id`=? AND `status`=? LIMIT 1";
		$res = $this->db->query($sql,array($id,'1'));
		return $res->result_array();
	}
	
	/************************************
	 * 
	 * 获取日志评论内容
	 * 
	 * @access public
	 ***********************************/
	function get_comment($start,$limit,$id)
	{
		
		$sql = "SELECT * FROM `mb_comments` 
				WHERE `contentid`=? 
				AND `status`=? 
				ORDER BY `id` DESC 
				LIMIT $start,$limit";
		$res = $this->db->query($sql,array($id,'1'));
		
		return $res->result_array();	
	}
	
	function get_total_comment($id)
	{
		$sql = "SELECT COUNT(id) AS num FROM `mb_comments`
				WHERE `contentid`=? 
				AND `status`=? 
				LIMIT 1";
		$res = $this->db->query($sql,array($id,'1'));
		
		$res = $res->result_array();
		
		if($res[0]['num']>5)
		{
			$n = $res[0]['num']-5;
		}
		else {
			$n = 0;
		}
		return $n;
	}
	
	function insert_comment($info='',$ip)
	{
		$contentid = $info['commentid'];
		$username = $info['username'];
		$comment = $info['comment'];
		$email = $info['email'];
		$url = $info['userurl'];
		$ctime = time();
		
		$sql = "INSERT INTO `mb_comments` 
				(`contentid`,`username`,`content`,`email`,`url`,`ctime`,`ip`,`status`)
				 VALUES('$contentid','$username','$comment','$email','$url','$ctime','$ip','1')";
		$this->db->query($sql);
		$n = $this->db->affected_rows(); 
		return $n;
	}
}

/* End of file content_model.php */ 
 
//* Location: ./application/models/content_model.php */